Chapter 5 Results
Questions:
Which part of NYC has restaurants with relatively low grades and relatively high grades?
Is there a relationship between the type of restaurants and the type of violations?
Are there any trends of scores for each cuisine type as time goes by?
For the franchise restaurants, what type of violations are most common and what might be the reasons?
## ── Attaching packages ────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.2
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 1.0.0 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ───────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(dplyr)
library(bookdown)
library(gganimate)
library(ggplot2)
library(gifski)
library(transformr)- First, take a look at the distributions of all restaurants inspected in NYC. Each point in the following map represents a unique restaurant. It is clear that Manhattan has the highest density of restaurant distribution among all boroughs. The density is also quite high along the coastline for Queens and Brooklyn compared to the densities in the other areas.
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
## [1] TRUE
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.71,-74&zoom=11&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
ggmap(nyc_map)+
geom_point(aes(x=restaurant$Longitude,y=restaurant$Latitude),data=restaurant,alpha=0.1,size=0.7)## Warning: Removed 24091 rows containing missing values (geom_point).

Here is an interactive map to show the number of restaurants in each selected area. Zoom-in and Zoom-out allow for inspection on smaller and larger scale.
library(leaflet)
library(leaflet.extras)
library(htmltools)
restaurant %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(
radius = 2,
label = ~ htmlEscape(`DBA`),
clusterOptions = markerClusterOptions()
) ## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively
## Warning in validateCoords(lng, lat, funcName): Data contains 429 rows with
## either missing or invalid lat/lon values and will be ignored